import axios from "../../utils/axios"

// pages/projectbase/projectbase.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchkey:"",
    projectlist:[],
    colors:["#165DFF","#00B42A","#FF7D00","#F53F3F","#F53F3F"]
  },
  async getprojectdetail(){
    console.log(this.data.searchkey)
    var token=getApp().globalData.accessToken
    var result=await axios.get("/project?flag=0&pass=1&name="+this.data.searchkey)
    console.log(result)
    var projects=result.content
    var projectlist=[]
    for (let i = 0; i < projects.length; i++) {
      const arr = projects[i];
      var tagarr=arr[4].split(",")
      var project={
        id:arr[0],
        name:arr[1],
        location:arr[2],
        count:arr[3],
        tags:tagarr,
        time:new Date(arr[5]),
        signcount:arr[6]
      }
      projectlist.push(project)
    }
    console.log(projectlist)
    this.setData({
      projectlist:projectlist
    })
  },
  creatproject:function(){
    wx.navigateTo({
      url:"../projectcreat/projectcreat"
    })
  },
  //data.currentTarget.dataset.i
 async projectmsg(e){
   var index=e.currentTarget.dataset.index
    wx.navigateTo({
      url:"../projectdetail/projectdetail?id="+this.data.projectlist[index].id
    })
  },
  getrearchkey:function(e){
    this.setData({
      searchkey:e.detail.value
    })
    this.getprojectdetail()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
 onLoad(){
   
  },
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getprojectdetail()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})